import { IDownloadDBFile, IDownloadDBTask, IHistory } from './../../model/DB';
import React from "react"

export interface IUser {
  name: string
  token: string
  infoToken: string
  account: string
  id: number
  tenant_id: number
}

export interface IDownloadTask extends IDownloadDBTask {
  files: IDownloadDBFile[]
}

export type IDownloadTaskMap = {
  [key in number]: IDownloadTask
}

export interface IConfig {
  port: number
}

export interface IGlobalContext {
  user: IUser
  loading: boolean
  /** 下载任务 */
  taskList: IDownloadDBTask[]
  /** 播放历史 */
  playHistory: IHistory[]
  /** 当前播放任务 */
  playTask?: IHistory

  config: IConfig
  
  setUserInfo: (value: IUser) => void

  addTask: (task: IDownloadDBTask, files: IDownloadDBFile[]) => void
  pauseTask: (task: IDownloadDBTask) => Promise<boolean>
  resumeTask: (task: IDownloadDBTask) => Promise<boolean>

  playCourse: (task: IHistory) => void
  updateCourse: (task: IHistory | undefined) => void

  deleteCourse: (task: IDownloadDBTask) => Promise<boolean>
}

const GlobalContext = React.createContext<IGlobalContext>(null!)

export default GlobalContext